package com.luocj.brvah_srl.adapter;

import android.content.Context;
import android.util.EventLog;
import android.view.PointerIcon;
import android.view.View;
import android.widget.Toast;

import com.blankj.ALog;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.luocj.brvah_srl.MainActivity;
import com.luocj.brvah_srl.R;
import com.luocj.brvah_srl.entity.MulEntity;
import com.luocj.brvah_srl.evnet.MyEvent;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

/**
 * Created by luocj515 on 2017/12/6.
 * 项目名称：BRVAHandSRL
 * 类描述：
 * 创建人：hasee
 * 创建时间：2017/12/6 10:25
 * 修改备注：
 */

public class MyAdapter extends BaseMultiItemQuickAdapter<MulEntity, BaseViewHolder> {

    public static final String TAG = MyAdapter.class.getSimpleName();
    private int[] images = new int[]{R.mipmap.b1, R.mipmap.b2, R.mipmap.b3};

    private Context mContext;

    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param mainActivity
     * @param data         A new list is created out of this one to avoid mutable list
     */
    public MyAdapter(MainActivity mainActivity, List<MulEntity> data) {
        super(data);
        this.mContext = mainActivity;
        init();
    }

    private void init() {
        addItemType(MulEntity.TEXT, R.layout.item_text);
        addItemType(MulEntity.IMAGE, R.layout.item_image);
        addItemType(MulEntity.TEXT_IMAGE, R.layout.item_text_image);
    }

    @Override
    protected void convert(final BaseViewHolder holder, MulEntity item) {
        switch (holder.getItemViewType()) {
            case MulEntity.TEXT:
                holder.setText(R.id.tv_type_one, ""+holder.getLayoutPosition());
                holder.getView(R.id.tv_type_one).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        ALog.aTag(TAG, holder.getLayoutPosition() + "---------->");
                        Toast.makeText(mContext, holder.getLayoutPosition() + "", Toast.LENGTH_SHORT).show();
                        EventBus.getDefault().post(new MyEvent(holder.getLayoutPosition() + ""));
                    }
                });
                break;
            case MulEntity.IMAGE:
                holder.setImageResource(R.id.iv_type_two, images[holder.getLayoutPosition() % 3]);
                break;
            case MulEntity.TEXT_IMAGE:
                holder.setText(R.id.tv_type_three, holder.getLayoutPosition() + "");
                holder.setImageResource(R.id.iv_type_three, images[(holder.getLayoutPosition() + 1) % 3]);
                break;
            default:
                break;
        }
    }

}
